/*
*快递分类统计
*/
/*
*业绩统计 
*/
import React from 'react';
import { Breadcrumb, Button, Input, Modal, message, Table, DatePicker } from 'antd';
import $ from 'jquery';
import moment from 'moment';
import Config from '../../../common/config';

const config = new Config();
const token = sessionStorage.getItem('token');
const RangePicker = DatePicker.RangePicker;
const InputGroup = Input.Group;

class ExpressClassify extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      dates: [moment().startOf('day'), moment().startOf('day').add(1, 'day')],
      data: [],
    }
  }
  //生命周期函数 加载前
  componentWillMount() {
    this.getdata();
  }
  //生命周期函数 加载完成后
  componentDidMount() {

  }
  //获取数据
  getdata(obj) {
    let data = {};
    if (obj) {
      data = obj;
    }
    $.ajax({
      type: 'get',
      url: config.CrmStatistics + '/shipStatistics',
      data: data,
      headers: { Authorization: 'Bearer ' + token },
      success: res => {
        console.log(res);
        const data = res.data.map(item => {
          item.key = item.id;
          return item;
        })
        this.setState({ data })
      }
    })
  }
  //获取搜索时间
  getDate(dates, dateStrings) {
    console.log(dates, dateStrings);
    this.setState({ dates })
  }
  //重置搜索
  resetSearch() {
    this.setState({
      name: '',
      dates: [moment().startOf('day'), moment().startOf('day').add(1, 'day')]
    })
  }
  //搜索
  searchData() {
    const { dates } = this.state;
    console.log(name, dates, new Date(dates[0]).getTime());
    const data = {
      startDate: new Date(dates[0]).getTime(),
      endDate: new Date(dates[1]).getTime() - 1,
    }
    this.getdata(data);
  }
  //表格行选择
  rowSelection() {
    return {
      onChange: (selectedRowKeys, selectedRows) => {
        console.log(selectedRowKeys, selectedRows);
      },
      onSelectAll: (selected, selectedRows, changeRows) => {
        console.log(selected, selectedRows, changeRows);
      },
    }
  };
  render() {
    const columns = [
      { title: '快递公司', dataIndex: 'name', key: 'name' },
      { title: '发货总数量', dataIndex: 'deliveryCount', key: 'deliveryCount', sorter: (a, b) => a.deliveryCount - b.deliveryCount },
      { title: '拒收数量', dataIndex: 'rejectionCount', key: 'rejectionCount', sorter: (a, b) => a.rejectionCount - b.rejectionCount },
    ]
    return (
      <div className='contentBox clearfix'>
        <div className='breadcrumb'>
          <Breadcrumb separator='>'>
            <Breadcrumb.Item>直销管理</Breadcrumb.Item>
            <Breadcrumb.Item>统计分析</Breadcrumb.Item>
            <Breadcrumb.Item>快递分类统计</Breadcrumb.Item>
          </Breadcrumb>
        </div>
        <div>
          <div style={{ overflow: 'hidden' }}>
            <div className='member-content-Search clearfix'>
              <div className='addetd addetd-a addetd-kk addr-yo'>
                <InputGroup compact>
                  <span className='chengge-a fkov-a' style={{ width: 100 }}>开始/结束时间:</span>
                  <div className='chengge-d' style={{ marginRight: 0 }}>
                    <RangePicker
                      ranges={{
                        '今天': [moment().startOf('day'), moment().endOf('day')],
                        '本周': [moment().startOf('week'), moment().endOf('week')],
                        '本月': [moment().startOf('month'), moment().endOf('month')],
                        '本年': [moment().startOf('year'), moment().endOf('year')],
                      }}
                      //disabledTime={this.disabledRangeTime.bind(this)}
                      showTime={{ hideDisabledOptions: true, format: 'HH:mm' }}
                      value={this.state.dates}
                      allowClear
                      onChange={this.getDate.bind(this)}
                      format="YYYY-MM-DD HH:mm"
                    />
                  </div>
                </InputGroup>
              </div>
              <Button type='primary' className='member-button-aa' onClick={() => { this.searchData() }}>搜索</Button>
              <Button type='primary' className='member-button-aa' onClick={() => { this.resetSearch() }}>重置</Button>
            </div>
          </div>
          <Table
            bordered
            defaultExpandAllRows
            columns={columns}
            rowSelection={this.rowSelection()}
            dataSource={this.state.data}
            pagination={false}
            className='totalTable'
          />
        </div>
      </div>
    )
  }
}

export default ExpressClassify;